package day07;
import java.util.Random;
import java.util.Scanner;
public class Exercise02 {
    public static void main(String[] args) {
/*        //1.猜数字小游戏
        Scanner scanner = new Scanner(System.in);
        int num = (int)(Math.random()*1000);
        System.out.println(num);
        while (true){
            System.out.println("猜吧！");
            int guess = scanner.nextInt();
            if (guess<num){
                System.out.println("猜小了!");
            }else if (guess>num){
                System.out.println("猜大了!");
            }else {
                System.out.println("恭喜你猜对了!");
                break;
            }
        }*/

        //2.需求:生成?位验证码(大写字母、小写字母、数字)
/*        String str = captcha(4);
        System.out.println(str);*/

        //3.找到2到100之间的所有素数(质数)
/*        int num =0;
        for (int i = 2; i <=100 ; i++) {
            boolean flag = true;
            for (int j = 2; j <=i/2 ; j++) {
                if (i%j==0){
                    flag=false;
                    break;
                }
            }
            if (flag){
                System.out.print(i+"\t");
                num++;
            }
        }
        System.out.println();
        System.out.println("共有"+num+"个");*/

        //4.计算机票价格
/*        Scanner sc = new Scanner(System.in);
        System.out.println("请输入机票价格:");
        double price = sc.nextDouble();
        System.out.println("请输入月份");
        int month = sc.nextInt();
        System.out.println("请选择机舱: 1.头等 2.商务 3.经济");
        int type = sc.nextInt();
        double scount = disScount(price,month,type);
        if (scount!=-1){
            System.out.println("最终的价格为:"+scount);
        }*/


/*      5.<<主持人大赛>>有6名评委给选手打分，要求分数范围为0到100之间的整数。
        选手的最后得分为：去掉最高分、最低分后的4个评委的平均分*/
        //获得分数
        double[] sorce = enDate();
        //计算总得分
        double total= calTotal(sorce);
        System.out.println("总得分为:"+total);
        //计算平均分
        double vag = calAvg(sorce);
        System.out.println("平均分为:"+vag);

    }
    //生成验证码创建captcha方法
    public static String captcha(int len){
        String str = "";
        char[] ch = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
                'q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G',
                'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X',
                'Y','Z','1','2','3','4','5','6','7','8','9'};
        Random ran = new Random();
        for (int i=0;i<len;i++){
            int index = ran.nextInt(ch.length);
            str+=ch[index];
        }
        return str;
    }
    //生成计算打折后的机票最终价格的discount方法
    public static double disScount(double price,int month,int type){
        double scount=0.0;
        if (month<1 || month>12){
            System.out.println("月份输入错误");
            return -1;
        }
        if (type<1 || type>3){
            System.out.println("无此舱型");
            return -1;
        }
        if (month>5 && month<10){
            switch (type){
                case 1:
                    scount=price*0.9;
                    break;
                case 2:
                    scount=price*0.85;
                    break;
                case 3:
                    scount=price*0.8;
                    break;
            }
        }else {
            switch (type){
                case 1:
                    scount=price*0.7;
                    break;
                case 2:
                    scount=price*0.65;
                    break;
                case 3:
                    scount=price*0.6;
                    break;
            }
        }
        return scount;
    }

    //录入分数创建enDate方法
    public static double[] enDate(){
        Scanner sc = new Scanner(System.in);
        double[] sorce = new double[6];
        for (int i=0;i<sorce.length;i++){
            System.out.println("第"+(i+1)+"位评委的分数为:");
            sorce[i]=sc.nextInt();
        }
        return sorce;
    }

    //计算总的分 生成calTotal方法
    public static double calTotal(double[] sorce){
        double total=0.0;
        double max = sorce[0];
        double min = sorce[0];
        for (int i = 0; i <sorce.length ; i++) {
            if (max<sorce[i]){
                max=sorce[i];
            }
            if (min>sorce[i]){
                min=sorce[i];
            }
        }
        for (int i = 0; i <sorce.length ; i++) {
            total+=sorce[i];
        }
        return total-max-min;
    }

    //计算平均分创建calAvg方法
    public static double calAvg(double[] sorce){
        double total = calTotal(sorce);
        double vag = total/(sorce.length-2);
        return vag;
    }

}
